package org.realteam.example.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.realteam.base.dao.BaseDao;
import org.realteam.base.service.BaseManager;
import org.realteam.example.model.Person;
import org.realteam.example.model.TestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

/**
 * Acts as a controller to handle actions related to registering a user.
 * 
 * @author bruce phillips
 * 
 */

@Controller
public class RegisterAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private static final Logger logger = Logger.getLogger(RegisterAction.class.getName());

	private Person personBean;

	@Autowired
	private BaseDao baseDao;

	@Autowired
	private BaseManager baseService;

	private Logger log = Logger.getLogger("app");

	@Action("register-input")
	public String input() throws Exception {

		logger.info("In input method of class Register");

		return INPUT;

	}

	@Action("test")
	public String test() throws Exception {
		logger.error("In input method of class Register");
		TestBean bean = new TestBean();
		bean.setName("Harry");
		baseService.saveObject(bean);

		return SUCCESS;

	}

	public String execute() throws Exception {

		logger.info("In execute method of class Register");

		// call Service class to store personBean's state in database

		return SUCCESS;

	}

	public Person getPersonBean() {
		return personBean;
	}

	public void setPersonBean(Person person) {
		personBean = person;
	}

}
